﻿

CREATE PROCEDURE [dbo].[proc_Employee_PostMove_Exec]

AS
	Declare @Count int
	--执行日期<=本月15日
	Set @Count = (select Count(Id) from employee_postmove where (isexec Is NULL or isexec=0) And execdate<=getdate())--execdate <= (DATEADD(mm, DATEDIFF(mm,0,Getdate()), 0) + 14 ))
	If(@Count>0)
		Begin
			--更新员工表
			Update Employee  Set Employee.PostId=Employee_PostMove.APostId,Employee.GradeId=Employee_PostMove.AGradeId,/*Employee.State=Employee_PostMove.AState*/
			Employee.PostCategory=Employee_PostMove.APostCategoryId,Employee.ZhiWu =Employee_PostMove.AZhiWu ,
			Employee.XZJB=Employee_PostMove.AXZJB,Employee.IsCore=Employee_PostMove.IsCore
			From Employee ,Employee_PostMove 
				    Where (Employee_PostMove.isexec Is NULL or Employee_PostMove.isexec=0) 
				          --And Employee_PostMove.execdate <= (DATEADD(mm, DATEDIFF(mm,0,Getdate()), 0) + 14)--执行日期<=本月15日
				          And Employee_PostMove.execdate <= Getdate() --2013.7.2 改为执行日期小于当天的异动全部更新
				          And Employee.Id=Employee_PostMove.EId
						  And Employee_PostMove.SecondAudit=1						  
			--SELECT Eid FROM Employee_PostMove 
			--				Where (Employee_PostMove.isexec Is NULL or Employee_PostMove.isexec=0) 
			--	            -- And Employee_PostMove.execdate <= (DATEADD(mm, DATEDIFF(mm,0,Getdate()), 0) + 14)--执行日期<=本月15日
			--				And Employee_PostMove.execdate <= Getdate()
			--				 And Employee_PostMove.SecondAudit=1 
			--更新岗位异动表
			Update Employee_PostMove Set IsExec=1 
							 Where (Employee_PostMove.isexec Is NULL or Employee_PostMove.isexec=0) 
				            -- And Employee_PostMove.execdate <= (DATEADD(mm, DATEDIFF(mm,0,Getdate()), 0) + 14)--执行日期<=本月15日
							 And Employee_PostMove.execdate <= Getdate()
							 And Employee_PostMove.SecondAudit=1
			  
		End
	RETURN



